#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> nums(n);
    
    for(int i = 0; i < n; i++){
        cin >> nums[i];
    }
    
    int maxVal = *max_element(nums.begin(), nums.end());
    int minVal = *min_element(nums.begin(), nums.end());
    
    int result = nums[0];
    int minDiff = abs(abs(nums[0] - maxVal) - abs(nums[0] - minVal));
    
    for(int i = 1; i < n; i++){
        int diff = abs(abs(nums[i] - maxVal) - abs(nums[i] - minVal));
        if(diff < minDiff || (diff == minDiff && nums[i] < result)){
            minDiff = diff;
            result = nums[i];
        }
    }
    
    cout << result << endl;
    return 0;
}